package com.yingsheng.bi.hks.repository.dao.service;

import com.yingsheng.bi.hks.basic.utils.Utils;
import com.yingsheng.bi.hks.repository.dao.mapper.ContractsMapper;
import com.yingsheng.bi.hks.repository.dao.po.Contracts;
import com.yingsheng.bi.hks.repository.dao.po.ContractsExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Contracts表的数据库操作服务
 * 要求说明：
 * 1.一般情况下,要求参数不超过5个时方法入参逐个声明
 * 2.一般情况下,要求条件不超过3个时要在方法名上体现
 * 3.最好对方法入参做一定校验,尤其是对条件参数至少要做非空校验
 *
 * @author 83686
 */
@Repository
public class ContractsDaoService implements DaoService {

    @Autowired
    private ContractsMapper contractsMapper;

    public boolean insert(Contracts contracts) {
        contracts.setId(Utils.genUUid());
        int result = contractsMapper.insert(contracts);
        return result == 1;
    }

    public List<Contracts> queryForApp(String userId, String state,String signState) {
        ContractsExample example = new ContractsExample();
        example.or(example.createCriteria().andStateEqualTo(state).andPartyIdAEqualTo(userId).andPartySignAEqualTo(signState));
        example.or(example.createCriteria().andStateEqualTo(state).andPartyIdBEqualTo(userId).andPartySignBEqualTo(signState));
        example.or(example.createCriteria().andStateEqualTo(state).andPartyIdCEqualTo(userId).andPartySignCEqualTo(signState));
        return contractsMapper.selectByExample(example);
    }

    public Contracts qryByContractId(String contractId) {
        ContractsExample example = new ContractsExample();
        example.createCriteria().andContractIdEqualTo(Long.valueOf(contractId));
        return contractsMapper.selectByExample(example).get(0);
    }

    public Contracts qryById(String id) {

        return contractsMapper.selectByPrimaryKey(id);
    }

    public void updateById(Contracts contracts){
        contractsMapper.updateByPrimaryKey(contracts);
    }
}
